package com.admin.business.workManagement.venusCycleCheckOrganization;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 循环计划公司审批等级表
 * @create: 2023-11-16 14:15:40
 **/
@Service("venusCycleCheckOrganizationService")
@Slf4j
public class VenusCycleCheckOrganizationService{

    @Resource
    VenusCycleCheckOrganizationDao venusCycleCheckOrganizationDao;

    /**
     * 添加循环计划公司审批等级表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - project_id:项目id
     *                   - user_id:用户id
     *                   - check_rank:审批等级
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-16 14:15:40
     */
    @OpenApi
    public Return addVenusCycleCheckOrganization(CDO cdoRequest) {
        venusCycleCheckOrganizationDao.addVenusCycleCheckOrganization(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新循环计划公司审批等级表数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - project_id:项目id
     *                   - user_id:用户id
     *                   - check_rank:审批等级
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-16 14:15:40
     */
    @OpenApi
    public Return updateVenusCycleCheckOrganizationById(CDO cdoRequest) {
        venusCycleCheckOrganizationDao.updateVenusCycleCheckOrganizationById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除循环计划公司审批等级表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-16 14:15:40
     */
    @OpenApi
    public Return deleteVenusCycleCheckOrganizationById(CDO cdoRequest){
        int count = venusCycleCheckOrganizationDao.deleteVenusCycleCheckOrganizationById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除循环计划公司审批等级表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-16 14:15:40
     */
    @OpenApi
    public Return deleteVenusCycleCheckOrganization(CDO cdoRequest) {
        int count = venusCycleCheckOrganizationDao.deleteVenusCycleCheckOrganization(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取循环计划公司审批等级表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-16 14:15:40
     */
    @OpenApi
    public Return getVenusCycleCheckOrganizationById(CDO cdoRequest) {
        CDO cdoMapperResult = venusCycleCheckOrganizationDao.getVenusCycleCheckOrganizationById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取循环计划公司审批等级表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-16 14:15:40
     */
    @OpenApi
    public Return getVenusCycleCheckOrganizationListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusCycleCheckOrganizationDao.getVenusCycleCheckOrganizationListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusCycleCheckOrganizationDao.getVenusCycleCheckOrganizationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取循环计划公司审批等级表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-16 14:15:40
     */
    @OpenApi
    public Return getVenusCycleCheckOrganizationListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusCycleCheckOrganizationDao.getVenusCycleCheckOrganizationListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusCycleCheckOrganizationDao.getVenusCycleCheckOrganizationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
